package com.szqhyxj.youxiangju.biz.merchantHome.my;

import com.google.gson.annotations.SerializedName;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.core.TokenManager;
import com.szqhyxj.youxiangju.biz.core.UserInfoManger;
import com.szqhyxj.youxiangju.sys.BaseResult;
import com.szqhyxj.youxiangju.sys.RetrofitFacade;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.POST;
import retrofit2.http.Query;

public class MyModel {

    static class IconItem {
        private int icon;
        private String title;
        private String subTitle;
        private int subTitleColor;
        private ICON id;

        IconItem(int icon, String title, String subTitle, int subTitleColor, ICON id) {
            this.icon = icon;
            this.title = title;
            this.subTitle = subTitle;
            this.subTitleColor = subTitleColor;
            this.id = id;
        }

        public int getIcon() {
            return icon;
        }

        public String getTitle() {
            return title;
        }

        public String getSubTitle() {
            return subTitle;
        }

        public int getSubTitleColor() {
            return subTitleColor;
        }

        public ICON getId() {
            return id;
        }
    }

    public enum ICON {
        DEVICE_ORDER,
        BANK_CARD,
        PAY_DEVICE,

        DEVIECEMANAGEMENT,
        POWER,
        RECOMMEND,
        TEAM,
        CONTACT,
        SETTING
    }

    public static List<IconItem> getIconItems() {
        int[] icons = {R.mipmap.goujidingdan, R.mipmap.yinhangka, R.mipmap.zhifushebei, R.mipmap.shebeiguanli, R.mipmap.shouquanshu01, R.mipmap.tuijianhaoyou, R.mipmap.hehuoren,
                R.mipmap.lianxikefu, R.mipmap.shezhi
        };
        String[] titles = {
                "购机订单", "银行卡", "支付设备", "设备管理", "授权书", "推荐好友", "合伙人",
                "联系客服", "设置"
        };
        String[] subTitles = new String[0];
        if (!TokenManager.INSTANCE.online()) {
            subTitles = new String[]{
                    "", "",
                    "", "", "", "", "", "400-843-3388", ""};
        } else {
            if (UserInfoManger.INSTANCE.getUser().getActiviteStatus() == 0) {
                subTitles = new String[]{
                        "", "", "未激活", "", "",
                        "", UserInfoManger.INSTANCE.getUser().getInviteName(),
                        UserInfoManger.INSTANCE.getUser().getServiceNumber(), ""};
            } else if (UserInfoManger.INSTANCE.getUser().getActiviteStatus() == 1) {
                subTitles = new String[]{
                        "", "",
                        "", "", "", "", UserInfoManger.INSTANCE.getUser().getInviteName(),
                        UserInfoManger.INSTANCE.getUser().getServiceNumber(), ""};
            }

        }

        int[] subTitleColors = {
                R.color.invitationColor, 0, 0,
                0, 0, R.color.gray,
                R.color.gray, 0, 0
        };
        ICON[] ids = {ICON.DEVICE_ORDER, ICON.BANK_CARD, ICON.PAY_DEVICE, ICON.DEVIECEMANAGEMENT, ICON.POWER, ICON.RECOMMEND, ICON.TEAM,
                ICON.CONTACT, ICON.SETTING
        };
        List<IconItem> iconItemList = new ArrayList<>();
        for (int i = 0; i < 9; i++) {

            iconItemList.add(new IconItem(
                    icons[i],
                    titles[i],
                    subTitles[i],
                    subTitleColors[i],
                    ids[i]
            ));
        }
        return iconItemList;
    }


    private interface MyService {
        @POST("user/info/warrant")
        Observable<BaseResult<WarrantBean>> warrant();

        @POST("order/pay/pos/deviceOrderPay")
        Observable<BaseResult<String>> deviceOrderPay(@Query("deviceNo") String deviceNo);

        @POST("profit/monthProfit")
        Observable<BaseResult<String>> monthProfit(
        );

    }


    public static Observable<BaseResult<WarrantBean>> getwarrant() {
        return RetrofitFacade.Companion.getRetrofit()
                .create(MyService.class)
                .warrant();
    }

    public static Observable<BaseResult<String>> deviceOrderPay(String deviceNo) {
        return RetrofitFacade.Companion.getRetrofit().create(MyModel.MyService.class).deviceOrderPay(deviceNo);
    }
    /**
     * 本月收益
     *
     * @return
     */
    public static Observable<BaseResult<String>> monthProfit() {
        return RetrofitFacade.Companion.getRetrofit().create(MyModel.MyService.class).monthProfit();
    }

    public static class WarrantBean {

        @SerializedName("partnerLicenseData")
        private String partnerLicenseData;

        @SerializedName("useraccount")
        private String useraccount;

        @SerializedName("username")
        private String username;

        public void setPartnerLicenseData(String partnerLicenseData) {
            this.partnerLicenseData = partnerLicenseData;
        }

        public String getPartnerLicenseData() {
            return partnerLicenseData;
        }

        public void setUseraccount(String useraccount) {
            this.useraccount = useraccount;
        }

        public String getUseraccount() {
            return useraccount;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getUsername() {
            return username;
        }

        @Override
        public String toString() {
            return
                    "Response{" +
                            "partnerLicenseData = '" + partnerLicenseData + '\'' +
                            ",useraccount = '" + useraccount + '\'' +
                            ",username = '" + username + '\'' +
                            "}";
        }
    }
}